gusucode.com > 各种VC自绘控件源码程序 > 各种VC自绘控件源码/code/SkinControls(自绘MFC基本控件 )/SkinControls/SkinControls/SkinUIProgress.cpp
#include "StdAfx.h" #include "SkinUIProgress.h" #include "SkinUIWnd.h" CSkinUIProgress::CSkinUIProgress(void) : m_bHorizontal(true), m_nMax(100), m_nMin(0), m_nPos(0) { } CSkinUIProgress::~CSkinUIProgress(void) { } LPCTSTR CSkinUIProgress::GetClass() const { return TEXT("SkinUIProgress"); } void CSkinUIProgress::PaintBkImage(CDC * pDC) { if( m_nMax <= m_nMin ) m_nMax = m_nMin + 1; if( m_nPos > m_nMax ) m_nPos = m_nMax; if( m_nPos < m_nMin ) m_nPos = m_nMin; long cxsrc = 0; long cysrc = 0; if (m_bHorizontal) { cxsrc = (m_nPos - m_nMin) * (m_rcItem.right - m_rcItem.left) / (m_nMax - m_nMin); cysrc = m_rcItem.bottom - m_rcItem.top; } else { cxsrc = m_rcItem.right - m_rcItem.left; cysrc = (m_rcItem.bottom - m_rcItem.top) * (m_nMax - m_nPos) / (m_nMax - m_nMin); } m_ImageBg.Draw(pDC->m_hDC, m_rcItem.left, m_rcItem.top, m_rcItem.Width(), m_rcItem.Height()); m_ImageProgress.Draw(pDC->m_hDC, m_rcItem.left, m_rcItem.top, cxsrc, cysrc); } void CSkinUIProgress::SetRange(int nLower, int nUpper) { m_nMin = nLower; m_nMax = nUpper; } void CSkinUIProgress::GetRange(int& nLower, int& nUpper) const { nLower = m_nMin; nUpper = m_nMax; } int CSkinUIProgress::GetValue() const { return m_nPos; } void CSkinUIProgress::SetValue(int nPos) { m_nPos = nPos; m_pParentWnd->InvalidateRect(&m_rcItem, FALSE); } void CSkinUIProgress::SetBgImage(LPCTSTR pszBg, DWORD imagetype) { m_ImageBg.Load(pszBg, imagetype); } void CSkinUIProgress::SetProgressImage(LPCTSTR pszProgress, DWORD imagetype) { m_ImageProgress.Load(pszProgress, imagetype); } bool CSkinUIProgress::IsHorizontal() { return m_bHorizontal; } void CSkinUIProgress::SetHorizontal(bool bHorizontal) { if( m_bHorizontal == bHorizontal ) return; m_bHorizontal = bHorizontal; }